package com.example.yml0528;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.yml.R;

import java.util.ArrayList;
import java.util.List;


public class OneFragment extends Fragment {

    List<ShangPin> splist;
    ListAdapter adapter;
    int[] imgi = {R.drawable.tou3, R.drawable.tou5, R.drawable.tou9, R.drawable.tou10, R.drawable.tou11, R.drawable.tou12};

    public OneFragment() {
        init();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        ListView tv = view.findViewById(R.id.lv);

        adapter = new ListAdapter(splist, inflater);
        tv.setAdapter(adapter);
        return view;
    }

    public void init() {
        splist = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            ShangPin sp = new ShangPin();
            sp.setName("商品" + i);
            sp.setImg(imgi[i % 6]);
            sp.setJianjie(i + ".66666666666666666666666666666666666666666666简介");
            sp.setPrice(5.0 + i*5);
            splist.add(sp);
        }

    }

}
